package com.yiwei.zhh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yiwei.zhh.R;
import com.yiwei.zhh.constant.UserGlobal;
import com.yiwei.zhh.util.ToastUtil;
import com.yiwei.zhh.util.UI;
import com.yiwei.zhh.view.V19FrameLayout;
import com.suke.widget.SwitchButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/6/10.
 */

public class GestureSettingActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.switch_btn)
    SwitchButton switchBtn;
    @BindView(R.id.switch_btn_two)
    SwitchButton switchBtnTwo;
    @BindView(R.id.txt_gesture_left)
    TextView txtGestureLeft;
    @BindView(R.id.txt_gesture_right)
    TextView txtGestureRight;
    @BindView(R.id.img_gesture_icon)
    ImageView imgGestureIcon;
    @BindView(R.id.layout_password)
    RelativeLayout layoutPassword;
    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guesture_setting);
        initBar();
        unbinder = ButterKnife.bind(this);
        init();
    }

    private void init() {
        setIsNeedCheckLogout(false);
        txtTitle.setText("手势密码");
        switchBtn.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                //TODO do your job
//                if (UI.toString(txtGestureLeft).equals("设置手势密码")) {
//                    ToastUtil.makeText(GestureSettingActivity.this, "您尚未绘制手势密码");
//                } else {
                UserGlobal.setIsOpenGuesture(isChecked);
                if(isChecked){
                    switchBtnTwo.setEnabled(true);
                }else {
                    switchBtnTwo.setEnabled(false);
                }
//                }

            }
        });

        switchBtnTwo.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                //TODO do your job
//                if (UI.toString(txtGestureLeft).equals("设置手势密码")) {
//                    ToastUtil.makeText(GestureSettingActivity.this, "您尚未绘制手势密码");
//                } else {
////                    UserGlobal.setIsOpenGuesture(isChecked);
//
//                }
                UserGlobal.setIsOpenGuestureRoot(isChecked);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        initbutton();
    }

    private void initbutton() {
        if (UserGlobal.getIsOpenGuesture()) {
            switchBtn.setChecked(true);
        } else {
            switchBtn.setChecked(false);
        }
        if (UserGlobal.getIsOpenGuestureRoot()) {
            switchBtnTwo.setChecked(true);
        } else {
            switchBtnTwo.setChecked(false);
        }
        if (isSetGuesture()) {
//            switchBtn.setEnabled(true);
            txtGestureLeft.setText("修改手势密码");

        } else {
//            switchBtn.setEnabled(false);
            txtGestureLeft.setText("设置手势密码");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        unbinder = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }

    @OnClick(R.id.layout_password)
    public void onViewClicked1() {
        if (UI.toString(txtGestureLeft).equals("设置手势密码")) {
            Intent intent = new Intent(this, CreateGestureActivity.class);
            intent.putExtra("is_check", true);
            startActivity(intent);
            overridePendingTransition(R.anim.right_enter, R.anim.left_out);
        } else {
            Intent intent = new Intent(this, GestureLoginActivity.class);
            intent.putExtra("is_check", true);
            startActivity(intent);
            overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                    Util.startActivity(this, GestureLoginActivity.class);
        }
    }
}
